package org.ResearchProject.mapper;

import org.ResearchProject.pojo.ResearchTask;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Map;

/**
 * 2024-12-13-19:28
 */
@Mapper
public interface ResearchTaskMapper {
    @Insert("insert into research_task(task_name,description,create_person,procession,start_time,end_time) " +
            "values(#{taskName},#{description},#{createPerson},#{procession},#{startTime},#{endTime})")
    void addTask(ResearchTask researchTask);
    @Delete("delete from research_task where id=#{taskId}")
    void deleteTask(Integer taskId);

    void updateTask(ResearchTask researchTask);
    @Select("select  research_task.* ,tutor.name as tutorName from research_task, tutor  where research_task.create_person=tutor.id" +
            " and research_task.id=#{taskId}")
    Map<String,Object> selectTaskById(Integer taskId);
    @Select("select  research_task.* ,tutor.name as tutorName from research_task, tutor  where research_task.create_person=tutor.id and research_task.create_person=#{tutorId}" )
    ArrayList<Map<String,Object>> tutorSelectAllTask(Integer tutorId);
    @Select("select research_task.*, tutor.name as tutorName, research_task_relationship.text " +
            "from research_task " +
            "join tutor on research_task.create_person = tutor.id " +
            "join research_task_relationship on research_task_relationship.task_id = research_task.id " +
            "where research_task_relationship.student_id = #{studentId}")
    ArrayList<Map<String, Object>> studentSelectAllTask(Integer studentId);
    @Insert("insert into research_task_relationship(task_id,student_id,start_time,end_time,tutor_id) " +
            "values(#{taskId},#{studentId},#{startTime},#{endTime},#{tutorId})")
    void giveTaskToStudent(Integer taskId, Integer studentId, LocalDateTime startTime, LocalDateTime endTime, Integer tutorId);
    @Update("UPDATE research_task_relationship SET text = #{text} " +
            "WHERE task_id = #{taskId} AND student_id = #{studentId}")
    void submitTask(Integer taskId, String text, Integer studentId);
}
